package com.deltabravomedia.theoldtoad;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.deltabravomedia.directions.DrivingDirections;
import com.deltabravomedia.directions.DrivingDirectionsFactory;
import com.deltabravomedia.directions.Placemark;
import com.deltabravomedia.directions.Route;
import com.deltabravomedia.directions.DrivingDirections.IDirectionsListener;
import com.deltabravomedia.directions.DrivingDirections.Mode;
import com.google.android.maps.GeoPoint;

public class Directions extends Activity implements IDirectionsListener{
	private ListView lv;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        lv = new ListView(this);
        TextView tv = new TextView(this);
        tv.setText("Searching for directions...");
        lv.setEmptyView(tv);
        
        setContentView(lv);
        
        int toLat = 0;
        int toLng = 0;
        int fromLat = 0;
        int fromLng = 0;
        
        Bundle extras = getIntent().getExtras(); 
        if(extras !=null)
        {
        	toLat = extras.getInt("toLat");
        	toLng = extras.getInt("toLng");
        	fromLat = extras.getInt("fromLat");
        	fromLng = extras.getInt("fromLng");
        }

        GeoPoint startPoint = new GeoPoint(fromLat, fromLng);
        GeoPoint endPoint = new GeoPoint(toLat, toLng);
        
        DrivingDirections.Mode mode = Mode.DRIVING; // or Mode.WALKING
        DrivingDirections directions = DrivingDirectionsFactory.createDrivingDirections();
        directions.driveTo(startPoint, endPoint, mode, this);
    }

	
	public void onDirectionsAvailable(Route route, Mode mode) {
		List<Placemark> placemarks = route.getPlacemarks();
		lv.setAdapter(new ArrayAdapter<Placemark>(this, R.layout.directionsrow, placemarks));
		lv.setClickable(false);
	}

	public void onDirectionsNotAvailable() {
		TextView tv = new TextView(Directions.this);
		tv.setText("Directions not available.");
        lv.setEmptyView(tv);
	}

}
